package com.lbh.cloudgallery.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lbh.cloudgallery.entity.MuseumEntity;
import com.lbh.cloudgallery.entity.ProductEntity;
import com.lbh.cloudgallery.service.MuseumService;
import com.lbh.cloudgallery.service.ProductService;
import com.xxx.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "前端-艺术馆模块")
@RestController
@RequestMapping("front/museum")
public class FrontMuseumController {

    @Autowired
    private MuseumService museumService;

    @Autowired
    private ProductService productService;

    //分页查询艺术馆
    @ApiOperation(value="分页查询艺术馆")
    @PostMapping("getMuseumList/{page}/{limit}")
    public R getMuseumList(@PathVariable long page, @PathVariable long limit){
        Page<MuseumEntity> pageMuseum=new Page<>(page,limit);
        Map<String,Object> map=museumService.getMuseumList(pageMuseum);

        return R.ok().setData(map);
    }

    //根据艺术馆id查询其艺术品
    @ApiOperation(value="根据艺术馆id查询艺术品")
    @GetMapping("getMuseumInfo/{id}")
    public R getMuseumInfo(@PathVariable long id){
        QueryWrapper<ProductEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("museum",id);
        List<ProductEntity> ProductList=productService.list(wrapper);

        return R.ok().setData(ProductList);
    }


    //查询所有艺术馆
    @ApiOperation(value="查询所有艺术馆")
    @PostMapping("getAllMuseumList")
    public R getAllMuseumList(){
        List<MuseumEntity> museumEntityList = museumService.list(null);
        return R.ok().setData(museumEntityList);
    }
}
